package com.campuscarbooking.api.dto;

import com.campuscarbooking.api.model.User;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

import java.time.LocalDateTime;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class UserDTO {
    private Long id;
    private String wxOpenid;
    private String phone;
    private String userType;
    private String nickname;
    private String avatarUrl;
    private Integer gender;
    private LocalDateTime createdAt;

    public static UserDTO fromEntity(User user) {
        if (user == null) {
            return null;
        }

        UserDTO dto = new UserDTO();
        dto.setId(user.getId());
        dto.setWxOpenid(user.getWxOpenid());
        dto.setPhone(user.getPhone());
        dto.setUserType(user.getUserType() != null ? user.getUserType().name() : null);
        dto.setNickname(user.getNickname());
        dto.setAvatarUrl(user.getAvatarUrl());
        dto.setGender(user.getGender());
        dto.setCreatedAt(user.getCreatedAt());

        return dto;
    }
} 